<script setup lang="ts">
import {onMounted, ref} from "vue";
import {getCurrentUser} from "../service/user";
import {userType} from "../models/user.js";
import {showFailToast, showSuccessToast} from "vant";
import TeamCard from "../components/TeamCard.vue";
import request from "../plugins/request";
import {teamType} from "../models/team";

const active = ref('join')

const createTeamList = ref<teamType[]>([])
const joinTeamList = ref<teamType[]>([])

// 获取当前用户 是否登录
const currentUser = ref({})
onMounted(async () => {
  // 用户是否登录
  currentUser.value = await getCurrentUser()

  // 获取创建人数数据
  {
    const result = await request.get('/team/list/create')
    const {code, data} = result
    if (code === 200) {
      createTeamList.value = data
    } else {
      showFailToast('查询创建的队伍失败')
    }
  }


  // 获取加入人数数据
  {
    const result = await request.get('/team/list/join')
    const {code, data} = result
    if (code === 200) {
      joinTeamList.value = data
    } else {
      showFailToast('查询加入的队伍失败')
    }
  }

  if (!currentUser.value){
    showFailToast('未登录')
  }
})


const click_lab = async () => {

}

</script>

<template>
  <div id="team_myself">
    <van-tabs v-model:active="active" @click-tab="click_lab" swipeable>
      <van-tab name="create">
        <template #title>
          <van-icon name="more-o"/>
          创建的队伍
        </template>
        <team-card v-if="createTeamList.length>0" :teamList="createTeamList"></team-card>
        <van-empty v-else description="暂无信息"/>
      </van-tab>
      <van-tab name="join">
        <template #title>
          <van-icon name="more-o"/>
          加入的队伍
        </template>
        <team-card v-if="joinTeamList.length>0" :teamList="joinTeamList"></team-card>
        <van-empty v-else description="暂无信息"/>
      </van-tab>
    </van-tabs>

  </div>

</template>


<style scoped>

</style>
